<template>
	<view class="pagesBox">
		<view style="position: sticky;top: 0%;z-index: 999;overflow: hidden;background-color: #f7f8fa;">
			<my-nav count="我的" color="#000" :bgImage="`${baseUrl}/static/index/bg01.png`" :isShow="false" :isSwitchTab="true"></my-nav>
		</view>
		<view class="pagesBgImg">
			<image :src="`${baseUrl}/static/index/bg01.png`" mode="widthFix" style="width: 100%;"></image>
			<image :src="`${baseUrl}/static/index/bg02.png`" mode="widthFix" style="width: 100%;" class="image2"></image>
		</view>
		<view class="pagesMain">
			<my-headInfo :headInfo="headInfo" :token="token"></my-headInfo>
			<view class="myOrderBox">
				<view class="titleBox">
				    <view class="titleLeft">订单中心</view>
					<view class="titleRight" @click="toOrder({url:'/pagesMy/order/list?status=null'})">
						查看全部<u-icon name="arrow-right" color="#777" size="28"></u-icon>
					</view>
				</view>
				<view class="menuBox">
					<block v-for="(item,index) in orderList" :key="index">
						<view class="menuItem" @click="toOrder(item)">
							<view class="menuImage">
								<image :src="item.image" style="width: 64rpx;height: 64rpx;"></image>
								<u-badge type="error" size="mini" :count="item.num" :offset="[-5,-15]"></u-badge>
							</view>
							<view class="menuText">{{item.text}}</view>
						</view>
					</block>
				</view>
			</view>
			<view class="myOrderBox">
				<view class="titleBox">
				    <view class="titleLeft">我的服务</view>
				</view>
				<my-menuBox :menuList="menuList" :menuType="2" :codeUrl="codeUrl"></my-menuBox>
			</view>
		</view>
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	import { isLogin } from "../../mixins/isLogin.js"
	import { isUpdateNew } from "../../mixins/isUpdateNew.js"
	export default {
		mixins:[isLogin,isUpdateNew],
		data() {
			return {
				baseUrl:this.$baseUrl,
				token:"",
				headInfo:{},
				orderList:[
					{image:this.$baseUrl+'/static/my/icon01.png',url:'/pagesMy/order/list?status=0',text:'待付款',num:0},
					{image:this.$baseUrl+'/static/my/icon02.png',url:'/pagesMy/order/list?status=1',text:'待发货',num:0},
					{image:this.$baseUrl+'/static/my/icon03.png',url:'/pagesMy/order/list?status=2',text:'待收货',num:0},
					{image:this.$baseUrl+'/static/my/icon04.png',url:'/pagesMy/order/list?status=4',text:'售后/退款',num:0}
				],
				// 常用功能
				menuList: [
					{icon: this.$baseUrl+"/static/my/icon05.png",title: "联系客服",url:'',isShow:true},
					{icon: this.$baseUrl+"/static/my/icon06.png",title: "地址信息",url:'/pagesMy/address/list?comePage=my',isShow:true},
					{icon: this.$baseUrl+"/static/my/icon07.png",title: "我的积分",url:'/pagesMy/jifen/jifen',isShow:true},
					{icon: this.$baseUrl+"/static/my/icon08.png",title: "积分收入",url:'/pagesMy/income/income',isShow:true},
					{icon: this.$baseUrl+"/static/my/icon09.png",title: "积分中心",url:'/pagesMy/center/center',isShow:true},
					{icon: this.$baseUrl+"/static/my/icon10.png",title: "我的营业额",url:'/pagesMy/turnover/turnover',isShow:false},
					{icon: this.$baseUrl+"/static/my/icon11.png",title: "我邀请的",url:'/pagesMy/invite/invite',isShow:true},
					{icon: this.$baseUrl+"/static/my/icon26.png",title: "我的分享码",url:'/pagesMy/invite/invite',isShow:true},
				],
				codeUrl:""
			};
		},
		onLoad(options) {
			if(options.uid){
				uni.setStorageSync('shareuid',options.uid)
			}
		},
		onShow() {
			this.token = uni.getStorageSync('token') || -1;
			this.updateNew();
			this.getUserInfo();
			this.getOrderList()
		},
		methods:{
			// 在这里用主要是为了验证token是否过期或是否是登录状态
			async getOrderList(){
				let res = await uni.$http('POST','order/list',{limit:1});
				if(res.code == 1){
					
				}else if(res.msg.includes('登录')){
					this.total = -1;
					uni.removeStorageSync("token")
					this.toLogin();
				}else{
					this.total = -1;
				}
			},
			async getUserInfo(){
				let res = await uni.$http('POST','user/userInfo');
				console.log("用户信息",res);
				if(res.code == 1){
					this.headInfo = res.data;
					if(res.data.identity == 10 || res.data.identity == 11){
						let index = this.menuList.findIndex(p=>{
							return p.title == "我的营业额"
						})
						let obj = this.menuList[index];
						obj.isShow = true;
						this.menuList.splice(index,1,obj)
					}
					if(res.data.identity > 1){
						this.getQrcode();
					}
				}else if(res.msg.includes('登录')){
					uni.setStorageSync('token',0);
					this.token = -1;
				}
			},
			async getQrcode(){
				let res = await uni.$http('POST','qrcode/getQrcode2');
				if(res.code == 1){
					this.codeUrl = res.data.qrcode_url;
				}
			},
			toOrder(item){
				let token = uni.getStorageSync('token') || 0;
				if(token){
					uni.navigateTo({
						url:item.url
					})
				}else{
					this.toLogin()
				}
				
			},
		},
		// onShareAppMessage(){
		// 	let pages = getCurrentPages()
		// 	let prePage = pages[pages.length - 1];
		// 	return{
		// 		path:`/${prePage.route}?uid=${uni.getStorageSync('uid')}`
		// 	}
		// },
		// onShareTimeline() {
		// 	return{
		// 		query:`uid=${uni.getStorageSync('uid')}`
		// 	}
		// }
	}
</script>

<style scoped lang="scss">
.pagesBox{
	.pagesBgImg {
		background-color: transparent;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		.image2{
			position: absolute;
			left: 0%;
			right: 0%;
			bottom: 0%;
		}
	}
	.pagesMain{
		padding: 12rpx 32rpx;
		position: relative;
		.fuwuBox{
			background-color: #FFFFFF;
			border-radius: 16rpx;
			padding: 16rpx;
		}
		.myOrderBox{
			background-color: #FFFFFF;
			border-radius: 16rpx;
			padding: 24rpx;
			margin: 16rpx 0rpx;
			.titleBox{
			    color: #FCDFB0;
			    margin-bottom: 24rpx;
			    display: flex;
				justify-content: space-between;
			    align-items: center;
			    .titleLeft{
					font-weight: 600;
					font-size: 28rpx;
					color: #16202B;
			        margin-right: 10rpx;
			        display: flex;
			    }
			    .titleRight{
					font-weight: 400;
					font-size: 26rpx;
					color: #777;
			        word-break: break-all;
					display: flex;
					justify-content: flex-end;
					align-items: center;
			    }
			}
			.menuBox{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.menuItem{
					width: 20%;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					align-items: center;
					.menuImage{
						font-size: 0%;
						display: flex;
						justify-content: center;
						align-items: center;
						position: relative;
					}
					.menuText{
						font-weight: 400;
						font-size: 24rpx;
						color: #444C55;
						margin-top: 14rpx;
					}
				}
			}
			.totalMain{
				margin-top: 24rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.itemBox{
					width: 49%;
					background: #EBF3FF;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					padding: 16rpx;
					.itemTitle{
						font-weight: 400;
						font-size: 24rpx;
						color: #A1A5AA;
						display: flex;
						justify-content: space-between;
						align-items: center;
						.itemTitleRight{
							font-weight: 400;
							font-size: 24rpx;
							color: #04449E;
							display: flex;
							justify-content: center;
							align-items: center;
						}
					}
					.itemMoney{
						font-weight: 600;
						font-size: 34rpx;
						color: #16202B;
						margin-top: 4rpx;
					}
				}
			}
		}
	}
}
</style>
<style>
	page{
		background-color: #f7f8fa;
	}
</style>